package com.atwork.wuhua.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.widget.ImageView;

import com.atwork.wuhua.R;
import com.atwork.wuhua.bean.LaunchBean;
import com.atwork.wuhua.utils.GlideUtils.GlideUtil;
import com.atwork.wuhua.utils.Util;
import com.atwork.wuhua.wrideg.StarBar;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

public class LaunchAdapter extends BaseQuickAdapter<LaunchBean.DataBean, BaseViewHolder> {
    private Context context;

    public LaunchAdapter(Context context, int layoutResId, @Nullable List<LaunchBean.DataBean> data) {
        super(layoutResId, data);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, LaunchBean.DataBean item) {
        helper.addOnClickListener(R.id.img_thumb);
        String distance = Util.getDistance(context, Double.parseDouble(item.getLongitude()), Double.parseDouble(item.getLatitude()));

        GlideUtil.loadImage(context, item.getThumb(), (ImageView) helper.getView(R.id.img_thumb));
        helper.setText(R.id.tv_address, item.getSite_name()).setText(R.id.tv_time, item.getDate() +"  "+ item.getTime())
                .setText(R.id.tv_start_name, "发起人：" + item.getCreate_member()).setText(R.id.tv_num, item.getJoin_count() + "/" + item.getLimit_count())
                .setText(R.id.tv_time, item.getDate() + item.getTime()).setText(R.id.tv_distance, distance);

        ((StarBar) helper.getView(R.id.starBar)).setIsOnTouch(false);

        ((StarBar) helper.getView(R.id.starBar)).setStarMark(Float.parseFloat(item.getStarts()));
    }
}
